package com.rxkj.controller;

import com.rxkj.entity.gnss.GnssDeviceVO;
import com.rxkj.entity.rainwater.StationInfo;
import com.rxkj.service.StationManageService;
import com.rxkj.utils.PageData;
import com.rxkj.utils.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Case;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 设备管理
 *
 * @author alex
 * @date 2022-11-03 19:11:08
 */
@Api(tags = "设备管理")
@RestController
@RequestMapping(value = "/station-api")
public class StationManageController {

    private static Logger logger = LoggerFactory.getLogger(StationManageController.class);

    @Autowired
    private StationManageService stationManageService;

    @ApiOperation("设备信息")
    @GetMapping("/getDevStationInfo/{devcode}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "devcode", required = true, value = "1,水雨情rtu;2,gnss设备;3,渗压渗流设备"),
            @ApiImplicitParam(name = "currentPage", required = false, value = "当前页码"),
            @ApiImplicitParam(name = "pageSize", required = false, value = "每页条数"),
            @ApiImplicitParam(name = "deviceName", required = false, value = "设备名称")
    })
    //@RoleLevel(2)
    public ResponseResult getDevStationInfo(@PathVariable(value = "devcode", required = true) int devcode,
                                            @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                            @RequestParam(value = "pageSize", required = false, defaultValue = "10") int pageSize,
                                            @RequestParam(value = "deviceName", required = false) String deviceName){
        switch (devcode) {
            case 1:
                //水雨情rtu
                List<StationInfo> qe1 = stationManageService.getHdrtuStationInfo();
                return qe1.size() > 0?new ResponseResult<StationInfo>().success("查询成功...", qe1) : ResponseResult.success("未查询到数据...", qe1);
            case 2:
                //gnss设备
                PageData<StationInfo> qe2 = stationManageService.getGnssDevInfo(currentPage, pageSize, deviceName);
                if (qe2.getRows().size() > 0) {
                    return new ResponseResult<PageData<StationInfo>>().success("查询成功...", qe2);
                } else {
                    return new ResponseResult<PageData<StationInfo>>().success("未查询到数据...", qe2);
                }
            case 3:
                //todo 渗压渗流设备
                return ResponseResult.success("未查询到数据...");
            default:
                return ResponseResult.success("未查询到数据...");
        }
    }

    @ApiOperation("一张图设备概况")
    @GetMapping("/onePicDevChartsInit")
    //@RoleLevel(2)
    public ResponseResult<Map<String, Object>> onePicDevChartsInit(){
        Map<String, Object> res = stationManageService.onePicDevChartsInit();
        return res != null? (ResponseResult<Map<String, Object>>) new ResponseResult().success("查询成功...", res) : (ResponseResult<Map<String, Object>>) new ResponseResult().success("未查询到数据...", res);
    }

}
